from flask import Flask, jsonify, request
from flask_cors import CORS

app = Flask(__name__)

CORS(app, resources=r'/*')


@app.route("/get_msg")
def index():
    ctx = {
        "code": 1,
        "msg": "成功",
        "data": [{
            "name": "老李"
        }, {
            "name": "老王"
        }, {
            "name": "老张"
        }, ]
    }
    print(ctx)
    return jsonify(ctx)


@app.route("/calc")
def calc_day():
    y = int(request.args.get("y"))
    m = int(request.args.get("m"))
    d = int(request.args.get("d"))
    alldays = 0
    for i in range(1, m):
        if i == 4 or i == 6 or i == 9 or i == 11:
            alldays += 30
        elif i == 2:
            if (y % 4 == 0 and y % 100 != 0 or y % 400 == 0):
                alldays += 29
            else:
                alldays += 28
        else:
            alldays += 31

    alldays += d
    print("这是我在后台打印的数据" + str(alldays))
    return jsonify({"alldays": alldays})


if __name__ == '__main__':
    app.run(debug=True)
